import React, { useEffect } from 'react';
import { append } from '../utils';

function main() {
  const arr = [100, 200, 300, 400];
  const iterator = arr[Symbol.iterator]();

  let done = false;

  while (!done) {
    const { value: v, done: d } = iterator.next();
    done = d;
    append(`done: ${d}, value: ${v}`);
  }

  append('----------------------------------------');

  const set = new Set(['张三', '李四', '王五']);
  const iteratorSet = set[Symbol.iterator]();
  done = false;

  while (!done) {
    const { value: v, done: d } = iteratorSet.next();
    done = d;
    append(`done: ${d}, value: ${v}`);
  }
}

export default function iterableDemo() {
  useEffect(main, null);

  return (
    <div id="content">
      <p>iterable</p>
    </div>
  );
}
